<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<%-- 填充head --%>
<layout:override name="head">
    <style>.block-heading img {margin-right: 8px;border-radius: 10%;width: 30px;}</style>
</layout:override>

<%-- 填充content --%>
<layout:override name="content">
    <div class="navbar">
        <div class="navbar-inner">
            <a href="${ctxPath}/" class="brand">
                <span class="first">${siteName}</span>
            </a>
        </div>
    </div>
    <div class="row-fluid">
        <div class="dialog">
            <div class="block">
                <p class="block-heading"><img src="${photourl}"/>您好：${nickname}，来自${type}的朋友！
                </p>
                <div class="block-body">
                    <form action="${ctxPath}/admin/binding" method="post">
                        <label>请使用邮箱激活帐号：</label>
                        <input type="email" value="${email}" name="email" required="required" original-title="推荐使用网易或QQ邮箱，&lt;br /&gt;部分邮箱可能收不到邮件！" class="span12"/>
                        <input type="hidden" name="id" value="${id}" required="required"/>
                        <input type="submit" value="确认" class="btn btn-primary pull-right"/>
                        <div class="clearfix"></div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</layout:override>

<%-- 填充script --%>
<layout:override name="script">
    <script type="text/javascript">
        $(function(){
            $('form').submit(function(){
                var email = $('input[name="email"]').val();
                if(/^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/.test(email)){
                    var dialog = $.dialog();
                    $.post($(this).attr("action")
                            , $('form').serialize()
                            , function (data){
                                if(data.code === 0){
                                    dialog.content('邮箱发送成功，请进入邮箱按提示完成绑定！').lock().time(2000);
                                    var email_url = '/';
                                    if (email.indexOf('mail') > 0) {
                                        email_url = 'http://' + email.substr(email.indexOf('@') + 1, email.length);
                                    } else {
                                        email_url = 'http://mail.' + email.substr(email.indexOf('@') + 1, email.length);
                                    }
                                    setTimeout(function(){
                                        location.href = email_url;
                                    }, 2000);
                                }else if(data.code === 1) {
                                    dialog.title('提示！');
                                    dialog.content('邮件发送失败，请重试！').lock().time(2000);
                                }else {
                                    dialog.content('请尝试重新登陆！').lock().time(1000);
                                    setTimeout(function(){
                                        location.href = "${ctxPath}/sign_in";
                                    }, 1000);
                                }
                            }
                    );
                } else {
                    $.dialog({content: "邮箱格式不对！", time: 1000});
                }
                return false;
            });
        });
    </script>
</layout:override>

<%@ include file="/commons/_layout_admin.jsp" %>